home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / preformatter.h < prev    next >
C/C++ Source or Header  |  2005-01-05  |  3KB  |  103 lines

  1. /***************************************************************************
  2.                         PreFormatter.cpp  -  description
  3.                              -------------------
  4.     begin                : Mo Jan 03 2005
  5.     copyright            : (C) 2005 by AndrΘ Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #ifndef PreFormatter_H
  19. #define PreFormatter_H
  20.  
  21. #define LB_CHARS " \t[](){}-+<>.:,;"
  22. #define WS_CHARS " \n\r\t"
  23. #define INDENT_MARKERS "{(="
  24.  
  25. #include <string>
  26. #include <iostream>
  27.  
  28. #include "stringtools.h"
  29.  
  30. namespace highlight {
  31.  
  32. /** \brief Class which provides intelligent line wrapping.
  33. * @author Andre Simon
  34. */
  35.  
  36. class PreFormatter{
  37. public:
  38.     /** Constructor
  39.     */
  40.     PreFormatter(bool wrap, bool replTabs);
  41.  
  42.     PreFormatter();
  43.  
  44.     ~PreFormatter();
  45.  
  46.     /**
  47.      \return True if current line can be wrapped again
  48.     */
  49.     bool hasMoreLines();
  50.  
  51.     /**
  52.      Sets new line to be wrapped
  53.      \param newline New line
  54.     */
  55.     void setLine(const std::string  newline);
  56.  
  57.     /**
  58.      The method will indent function calls and statements
  59.      \return Next line
  60.     */
  61.     std::string  getNextLine();
  62.  
  63.     /**
  64.      \return True if lines following open braces should be indented
  65.     */
  66.     bool indentCode();
  67.  
  68.     /**
  69.       \param maxlength max. length of output lines
  70.       \param indentAfterOpenBraces set true if lines should be indented after braces
  71.     */
  72.     void setWrappingProperties(unsigned int maxlength=80, bool indentAfterOpenBraces=true);
  73.  
  74.     /**
  75.       \param num number of spaces which replace a tab
  76.     */
  77.  
  78.     void setNumberSpaces(unsigned int num);
  79.  
  80.     /**
  81.       \return true if preformatting is enabled
  82.     */
  83.     bool isEnabled(){
  84.       return wrapLines || replaceTabs;
  85.     }
  86.  
  87. private:
  88.  
  89.     unsigned int maxLineLength;
  90.  
  91.     std::string line, wsPrefix;
  92.     unsigned int index;
  93.     unsigned int numberSpaces;
  94.     size_t wsPrefixLength;
  95.     bool hasMore, indentAfterOpenBraces;
  96.     bool redefineWsPrefix;
  97.     bool wrapLines, replaceTabs;
  98. };
  99.  
  100. }
  101.  
  102. #endif
  103.